 package SwingLib;
 import javax.swing.JOptionPane;
 /**
  * A class to simplify the throwing of dialog messages.
  * Based on a class written in PHP for the Callicore 
  * framework created by Elizabeth Smith
  * @author Jace Ferguson
  *
  */
 public class Message {
	 public static final int ERROR =  JOptionPane.ERROR_MESSAGE;
	 public static final int WARNING = JOptionPane.WARNING_MESSAGE;
	 public static final int INFO = JOptionPane.INFORMATION_MESSAGE;
	 public static final int QUESTION = JOptionPane.QUESTION_MESSAGE;
	 
	 private String title;
	 private String message;
	 private int messageType;
	 private int result;
	 /**
	  * Constructor that shows a custom message in default dialog
	  * @param message	String message
	  */
	 public Message(String message)
	 {
		 this.title = "Message";
		 this.message = message;
		 this.messageType = Message.INFO;
		 this.displayMessageDialog();
	 }
	 /**
	  * Constructor that has a custom message and custom title but default icon
	  * @param message	String message for dialog
	  * @param title	String title for dialog
	  */
	 public Message(String message, String title)
	 {
		 this.title = title;
		 this.message = message;
		 this.messageType = Message.INFO;
		 this.displayMessageDialog();
	 }
	 /**
	  * Constructor specifying a custom dialog
	  * @param message	String message for the dialog
	  * @param title	String title for the dialog
	  * @param messageType	String icon type for the dialog
	  */
	 public Message(String message, String title, int messageType)
	 {
		 this.title = title;
		 this.message = message;
		 this.messageType = messageType;
		 this.displayMessageDialog();
	 }
	 /**
	  * Shows the actual message dialog.
	  */
	 private void displayMessageDialog()
	 {
		 if(this.messageType != Message.ERROR && this.messageType != Message.WARNING && this.messageType != Message.QUESTION)
		 {
			 this.messageType = Message.INFO;
		 }
		 if(this.messageType == Message.QUESTION)
		 {
			 this.result = JOptionPane.showConfirmDialog(null, this.message, this.title, JOptionPane.YES_NO_OPTION);
		 }
		 else
		 {
			 JOptionPane.showMessageDialog(null, this.message, this.title, this.messageType);
		 }
	 }
	 /**
	  * Gets the result from the dialog. 
	  * @return	integer result from the dialog button clicked
	  * @post $return == 0 || $return == 1	$return == 1 if the "No" button is pressed
	  */
	 public int getResult()
	 {
		 return this.result;
	 }
}


